package com.yunxitest.yunxitest.utils;

import android.annotation.SuppressLint;
import android.util.Log;

import java.text.SimpleDateFormat;
import java.util.Date;

public class Common {

	
	/**
	 * 获取当前时间的字符串
	 * 
	 * @return
	 */
	@SuppressLint("SimpleDateFormat")
	public static String getNowTime() {
		SimpleDateFormat sDateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss:SSS");
		Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
		String str = sDateFormat.format(curDate);
		return str;
	}
	/**
	 * 获取当前时间的字符串
	 * 
	 * @return
	 */
	@SuppressLint("SimpleDateFormat")
	public static String getNowTime2() {
		SimpleDateFormat sDateFormat = new SimpleDateFormat(
				"yyyyMMddHHmmss");
		Date curDate = new Date(System.currentTimeMillis());// 获取当前时间
		String str = sDateFormat.format(curDate);
		return str;
	}

	public static String getTimeByTimeStamp(long time) {
		SimpleDateFormat sDateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		Date curDate = new Date(time);// 获取当前时间
		String str = sDateFormat.format(curDate);
		return str;
	}
	
	/**
	 * bytes转换成十六进制字符串
	 * 
	 * @param  b byte数组
	 * @return String 每个Byte值之间空格分隔
	 */
	public static String byte2HexStr(byte[] b) {
		try {
			String stmp = "";
			StringBuilder sb = new StringBuilder("");
			for (int n = 0; n < b.length; n++) {
				stmp = Integer.toHexString(b[n] & 0xFF);
				sb.append((stmp.length() == 1) ? "0" + stmp : stmp);
			}
			return sb.toString().toLowerCase().trim();
			// return sb.toString().toUpperCase().trim();
		} catch (Exception e) {
			e.printStackTrace();
			Log.e("sean", "^^^^^:" + e.toString());
			return "00";
		}

	}


	public static String generateTag() {
		StackTraceElement stackTraceElement = Thread.currentThread().getStackTrace()[4];
		String callerClazzName = stackTraceElement.getClassName();
		callerClazzName = callerClazzName.substring(callerClazzName.lastIndexOf(".") + 1);
		String tag = "%s.%s(:%d)";
		tag = String.format(tag, new Object[]{callerClazzName, stackTraceElement.getMethodName(), Integer.valueOf(stackTraceElement.getLineNumber())});
		return tag;
	}
}
